package com.wmuj.controller;


import com.wmuj.annotation.LogOperation;
import com.wmuj.pojo.Dept;
import com.wmuj.pojo.Result;
import com.wmuj.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 部门管理
 */

@Slf4j
@RequestMapping("/depts")
@RestController
public class DeptController {

    @Autowired
    private DeptService deptService;

  /**
   *  @RequestMapping(path = "/depts",method = RequestMethod.GET)
   *     查询部门数据
   */
  @GetMapping
  public Result list() {
    List<Dept> deptList=deptService.findAll();
    return  Result.success(deptList);
    }
    /**
     * 根据id删除部门数据
     */
    @LogOperation

    @DeleteMapping
    public Result delete( Integer id){
      log.info("根据ID删除部门：{}",id);
      deptService.delete(id);
      return Result.success();
    }

    /**
     * 新增部门
     */
    @LogOperation

    @PostMapping
    public Result add(@RequestBody Dept dept){
      log.info("新增部门：{}",dept);
      deptService.add(dept);
      return Result.success();
    }

    /**
     * 根据id 查询部门数据
     */
    @GetMapping("/{id}")
    public Result findById(@PathVariable Integer id){
      log.info("根据ID查询部门：{}",id);
      Dept dept=deptService.findById(id);
      return Result.success(dept);
    }
    /**
     * 根据id 更新部门数据
     */
    @LogOperation

    @PutMapping
    public Result update(@RequestBody Dept dept){
      log.info("根据ID更新部门：{}",dept);
      deptService.update(dept);
      return Result.success();
    }

}
